****************************************************************************************************
*This file builds vars on replaceability by robots from the Census/ACS and Graetz & Michaels (2018)*
****************************************************************************************************

use "$list/czones_list.dta", clear

merge m:1 czone using "$clean_data_lmarket/czone1990_educationReplaceability.dta", assert(3) nogenerate
merge m:1 czone using "$clean_data_lmarket/czone2008_educationReplaceability.dta", assert(3) nogenerate

foreach var of varlist ipums_* {
quiet replace `var' = 0 if mi(`var')
}

*Replaceability
gen d_rep = 100*((ipums_rep_2008/ipums_emp_2008)-(ipums_rep_1990/ipums_emp_1990))

gen share_rep_1990 = 100*ipums_rep_1990/ipums_emp_1990


foreach educ in b a l {
gen d_rep_`educ' = 100*((ipums_rep_`educ'_2008/ipums_emp_`educ'_2008)-(ipums_rep_`educ'_1990/ipums_emp_`educ'_1990))

gen share_rep_`educ'_1990 = 100*ipums_rep_`educ'_1990/ipums_emp_`educ'_1990

}

*Keep variables of interest
keep czone share_* d_* ipums_emp_1990

save "$final_data_outcomes/czone_EducationReplaceability.dta", replace






